Skip to content

ENH/TST: Allow more keywords to ensure_clean #30915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2020

Conversation

gfyoung
Copy link
Member

@gfyoung gfyoung commented Jan 11, 2020

These keywords will be passed through to tempfile constructor functions.

Follow-up:

#30771 (comment)

These keywords will be passed through to
tempfile constructor functions.

Follow-up:

pandas-dev#30771
@gfyoung gfyoung added Enhancement Testing pandas testing functions or related to the test suite labels Jan 11, 2020
@gfyoung gfyoung added this to the 1.1 milestone Jan 11, 2020
@@ -485,23 +485,37 @@ def ensure_clean(filename=None, return_filelike=False):
return_filelike : bool (default False)
if True, returns a file-like which is *always* cleaned. Necessary for
savefig and other functions which want to append extensions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don’t list encoding , mode here explicitly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and in the signature

Copy link
Member Author

@gfyoung gfyoung Jan 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.python.org/3/library/tempfile.html#tempfile.TemporaryFile
https://docs.python.org/3/library/tempfile.html#tempfile.mkstemp

encoding and mode are not accepted in mkstemp.

The only shared parameters are prefix, suffix (corresponds to filename in our signature), and dir. Not sure that the remaining two need exposure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking back on comment in OP is the main thing needed for now just encoding? If so I think better to just list explicitly and not pass to mkstemp

Copy link
Member Author

@gfyoung gfyoung Jan 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so I think better to just list explicitly and not pass to mkstemp

The whole point is to use the **kwargs in ensure_clean as a pass through to mkstemp or TemporaryFile, depending on whether return_filelike is true or false.

Explicitly listing arguments that apply to one but not the other is going to be confusing. What is being done is a lot more extensible in the long-run.

@gfyoung
Copy link
Member Author

gfyoung commented Jan 14, 2020

@WillAyd @jreback : Any further thoughts on this?

@WillAyd
Copy link
Member

WillAyd commented Jan 14, 2020

I would still vote for explicit arguments if anything but certainly open to input of others

@gfyoung
Copy link
Member Author

gfyoung commented Jan 14, 2020

@pandas-dev/pandas-core : Thoughts? There seems to be some impasse regarding whether we should surface explicit arguments. I'm all for being explicit, but I also want them to make sense for both mkstemp and TemporaryFile and not just one.

As we have it, filename is used consistently for both constructor functions.

@jreback jreback merged commit 8718877 into pandas-dev:master Jan 15, 2020
@jreback
Copy link
Contributor

jreback commented Jan 15, 2020

this is fine as its only for testing, thanks @gfyoung

however, I think it would be interesting to separate ensure_clean to 2 functions, e.g. ensure_clean_dir and ensure_clean_file; then you could have named keywords.

not sure how much work that would be but might be a good followup .

@gfyoung gfyoung deleted the ensure-clean-enhance branch January 15, 2020 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants